package com.mashibing.api.controller;

import com.mashibing.api.enums.SmsCodeEnum;
import com.mashibing.api.filter.CheckFilterContext;
import com.mashibing.api.form.SingleSendForm;
import com.mashibing.api.util.R;
import com.mashibing.api.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description:
 * @author: hdr
 * @PACKAGE_NAME: com.com.mashibing.api.controller
 * @DATE: 2025/2/13
 */
@RestController
@RequestMapping("/sms")
@Slf4j
public class SmsController {

    @Resource
    private CheckFilterContext checkFilterContext;

    @PostMapping(value = "/single_send",produces = "application/json;charset=utf-8")
    public ResultVO singleSend(@RequestBody @Validated SingleSendForm singleSendForm, BindingResult bindingResult){
        //1. 校验参数
        if (bindingResult.hasErrors()){
            String msg = bindingResult.getFieldError().getDefaultMessage();
            log.info("【接口模块-单条短信Controller】 参数不合法 msg = {}",msg);
            checkFilterContext.check(singleSendForm);
            return R.error(SmsCodeEnum.PARAMETER_ERROR.getCode(),msg);
        }
        return R.ok();
    }
}
